#include <iostream>
using namespace std;
using ll=long long;
const int N=1e5+10;
int dp[N][26];
int main() {

	int n;
	cin>>n;
	string str;
	cin>>str;
	for(int i=str.size()-1;i>=0;--i){
		int nIdx=str[i]-'a';
		for(int j=0;j<26;++j){
			dp[i][j]=dp[i+1][j];
		}
		++dp[i][str[i]-'a'];
	}
	ll nRet=0;
	for(int i=0;i<static_cast<int>(str.size());++i){
		int nIdx=str[i]-'a';
		for(int j=0;j<26;++j){
			if(j==nIdx || dp[i][j]<2){
				continue;
			}
			nRet+=dp[i][j]*(dp[i][j]-1)/2;
		}
	}
	cout<<nRet<<endl;
	
	return 0;
}
